package com.leyou;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Supplier;

class Student {
    private String name;
    private int score;

    public Student(){

    }

    public Student(String name,int score){
        this.name = name;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public static int compareStudentByScore(Student student1,Student student2){
        return student1.getScore() - student2.getScore();
    }


    public int compareByScore(Student student){
        return this.getScore() - student.getScore();
    }
}

class StudentComparator {
    public int compareStudentByScore(Student student1,Student student2){
        return student2.getScore() - student1.getScore();
    }
}

public class test{

    @Test
    public void Test(){

        Student student1 = new Student("zhangsan",60);
        Student student2 = new Student("lisi",70);
        Student student3 = new Student("wangwu",80);
        Student student4 = new Student("zhaoliu",90);
        List<Student> students = Arrays.asList(student1,student2,student3,student4);

        students.sort((o1, o2) -> o1.getScore() - o2.getScore());
//        students.sort(new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return o1.getScore() - o2.getScore();
//            }
//        });
        students.forEach(student -> System.out.println(student.getScore()));

        System.out.println("==============================================");
        students.sort(Student::compareStudentByScore);
        students.forEach(student -> System.out.println(student.getScore()));


        System.out.println("==============================================");
        StudentComparator studentComparator = new StudentComparator();
        students.sort(studentComparator::compareStudentByScore);
        students.forEach(student -> System.out.println(student.getScore()));

        System.out.println("==============================================");
        students.sort(Student::compareByScore);
        students.forEach(student -> System.out.println(student.getScore()));

        System.out.println("==============================================");
        Supplier<Student> supplier = Student::new;
        System.out.println(supplier.get());

    }
    //60
    //70
    //80
    //90
    //==============================================
    //60
    //70
    //80
    //90
    //==============================================
    //90
    //80
    //70
    //60
    //==============================================
    //60
    //70
    //80
    //90
    //==============================================
    //com.leyou.Student@424c0bc4

}

